home *** CD-ROM | disk | FTP | other *** search
/ Video Toaster 4.2 / Video Toaster v4.2.iso / programs / flyercalibrate < prev    next >
Text File  |  1995-12-26  |  15KB  |  552 lines

  1. /* Flyer Auto-Calibration, Version 17-Dec-94, by SKell, NewTek Inc.  */
  2. /* Updated and error checking added By Bob C. 26-Dec-95              */
  3.  
  4. OPTIONS RESULTS
  5. numeric digits 12
  6.  
  7. /*--------------------------------------------------------*/
  8. /* You may need to adjust these "assigns" for your system */
  9.  
  10. TOAST = "Toaster:Programs/"
  11. FLYER = "Flyer_Support/C/"
  12.  
  13. FLYER = TOAST||FLYER
  14.  
  15. /*-------------------------------------------------*/
  16. /* Lets make sure they're not installed yet.       */
  17.  
  18. remlib("ToasterARexx.port")
  19. remlib("rexxmathlib.library")
  20.  
  21. say "Flyer Auto-Calibration, Version 26-Dec-95"
  22. say
  23.  
  24. IF exists(FLYER'PlayClip')=0 then do
  25.         say "ERROR:"
  26.         say " The file 'Toaster:Programs/Flyer_Support/C/PlayClip' is missing!"
  27.         say " You may need to reinstall your flyer software."
  28.         call GetOutaHere(" Flyer Calibration was not successful.")
  29.         end
  30.  
  31. if exists(FLYER'SetFloobyCal')=0 then do
  32.         say "ERROR:"
  33.         say " The File 'Toaster:Programs/Flyer_Support/C/SetFloobyCal' is missing!"
  34.         say " You may need to reinstall your flyer software."
  35.         call GetOutaHere(" Flyer Calibration was not successful.")
  36.         end
  37.  
  38. if exists(FLYER'CalibNew')=0 then do
  39.         say "ERROR:"
  40.         say " The file 'Toaster:Programs/Flyer_Support/C/CalibNew' is missing!"
  41.         say " You may need to reinstall your flyer software."
  42.         call GetOutaHere(" Flyer Calibration was not successful.")
  43.         end
  44.  
  45. if exists(FLYER'SetPlayMode')=0 then do
  46.         say "ERROR:"
  47.         say " The file 'Toaster:Programs/Flyer_Support/C/SetPlayMode' is missing!"
  48.         say " You may need to reinstall your flyer software."
  49.         call GetOutaHere(" Flyer Calibration was not successful.")
  50.         end
  51.  
  52. if exists(FLYER'voidall')=0 then do
  53.         say "ERROR:"
  54.         say " The file 'Toaster:Programs/Flyer_Support/C/Voidall' is missing!"
  55.         say " You may need to reinstall your flyer software."
  56.         call GetOutaHere(" Flyer Calibration was not successful.")
  57.         end
  58.  
  59. TestClip=""
  60.  
  61. /*------------------------------------------*/
  62. if pos("ToasterARexx.port" , show('Ports'))=0 then do
  63.  
  64. say
  65. say "Please wait for the Switcher to load."
  66.  
  67.  
  68. call pragma('d',TOAST)
  69.  
  70. address command
  71. 'run >nil: VideoToaster'
  72. address
  73.  
  74. /* Wait for the Switcher to come up */
  75.  
  76.    waitcount=0
  77.    do while pos("ToasterARexx.port" , show('Ports'))=0
  78.  
  79. address command
  80. 'wait 1'
  81. address
  82.  
  83.       waitcount = waitcount+1
  84.  
  85.       if(waitcount > 40) then do
  86.          say "The Switcher Failed to Load!"
  87.          say "Maybe you want to try again?"
  88.          exit
  89.       end
  90.    end
  91. end
  92.  
  93. addlib("ToasterARexx.port" , 0)
  94. SWITCHER(TOWB)
  95.  
  96. /* The Switcher is now up and running       */
  97. /*------------------------------------------*/
  98. /* calibrate the genlock                    */
  99.  
  100. say "Calibrating the Flyer Genlock."
  101.  
  102. address command
  103. FLYER'calibnew >nil: GC'
  104. 'c:wait 2'
  105. FLYER'SetFloobyCal >nil: 0 10 0 0'  /* reset some stuff in the Flyer */
  106. address
  107.  
  108. if ~exists("ENV:CalibResult") then do
  109.    say
  110.    say "ERROR:"   
  111.    say " The program CalibNew malfunctioned preventing me from calibrating"
  112.    say " your Flyer. This could be caused by:"
  113.    say
  114.    say " 1) Incompatability with your currently installed Amiga OS."
  115.    say "    (I.E. system with an old mathieedoubbas.library in KickStart)" 
  116.    say " 2) Lack of a Flyer in your computer."
  117.    say " 3) Your Flyer software not installed properly"
  118.    say
  119.    call GetOutaHere(" If the problem persists, contact NewTek for help.")
  120.    end
  121.  
  122. open(in,"ENV:CalibResult",'read')
  123. instring = readln(in)
  124. close(in)
  125. parse value instring with result
  126.  
  127. if (result ~= 0.0)  then do
  128.    say
  129.    say "ERROR:"   
  130.    say " A Problem was detected during Flyer genlock calibration."      
  131.    say " I got an error number of "result
  132.    say " You may need to power down, and then try again."
  133.    GetOutaHere(" If the problem persists, contact NewTek for help.")
  134. end
  135.  
  136. /*------------------------------------------*/
  137.  
  138. /* See if an existing TestSignal clip exists. If so, use it. */
  139. count=0
  140. volume=1
  141. do until((TestClip ~= "") | (volume=""))
  142.    volume=SWITCHER(FLYV,count,1)    /* see what Flyer Video volumes exist */
  143.    count=count+1
  144.  
  145.    if(volume ~= "") then do
  146.       clipname=value("volume")':TestSignal'
  147.       if(exists(clipname)) then TestClip=clipname
  148.    end
  149. end
  150.  
  151. if(TestClip = "") then do
  152.    say "Creating a Flyer Test Clip..."
  153.  
  154.    TestClip=SWITCHER(FLY1)    /* create a test clip */
  155.  
  156.    if(TestClip="") then do
  157.       say
  158.       say "ERROR:"
  159.       say " I was unable to create a Test Clip on one of your Flyer drives."
  160.       say 
  161.       say " This could be caused by:"
  162.       say "  1) Your Flyer drives are full."
  163.       say "  2) No Flyer drive attached to your Flyer."
  164.       say "  3) Flyer drives not mounted."
  165.       say ""
  166.       say " You may want to power down, and then try again."
  167.       GetOutaHere(" If the problem persists, contact NewTek for help.")
  168.    end
  169.  
  170.    say "Created '"TestClip"' test clip."
  171. end
  172.  
  173. /**********************************/
  174.  
  175. address command
  176. FLYER'playclip >nil: 0 0 0 "'TestClip'" 0 0 0 1 0'
  177. address
  178.  
  179. SWITCHER(TOSW)
  180. SWITCHER(M003)
  181. SWITCHER(P003)
  182.  
  183. if(ConnectLoopBack()=FALSE) then do
  184.  
  185.    /* see if the user ever did any autohue */
  186.    if(SWITCHER(STAT,DHUE) < 0) then do
  187.       /* The user has never AutoHued their Toaster, so set Digital Phase */
  188.  
  189.       say "Calibrating the Toasters digital phase."
  190.       best=CaliDigitalPhase()
  191.       SWITCHER(DHUE,best+256)
  192.       SWITCHER(MKHS)
  193.    end
  194.    else do
  195.       /* is the current Digital Phase Error > 3 degrees = (65536*sine(error)) ?*/
  196.       if(abs(SWITCHER(DH3E)) > 3430) then do
  197.          SWITCHER(TOWB)
  198.          say "Do you have a video source connected to input 1 of your Toaster (y/n)?"
  199.          pull myhair
  200.          if (left(myhair,1) ~= "N") then do
  201.             say "Your Toaster may need AutoHueing."
  202.             say "You should Quit this script, AutoHue the Toaster,"
  203.             say "and then run this script again."
  204.             say "Do you want to continue this script anyway (y/n)?"
  205.             pull myhair
  206.             if (left(myhair,1) ~= "Y") then do
  207.                SWITCHER(TOSW)
  208.                SWITCHER(NOIQ)
  209.                SWITCHER(TOWB)
  210.                remlib("ToasterARexx.port")
  211.                exit
  212.             end
  213.             else do
  214.                say "WARNING!"
  215.                say "Because you have chosen to skip Toaster AutoHueing,"
  216.                say "your Flyers playback hue may not be calculated accurately."
  217.             end
  218.          end
  219.  
  220.          say "Is it OK for me to adjust your Toaster Digital Hue (y/n)?"
  221.          pull myhair
  222.          SWITCHER(TOSW)
  223.  
  224.          if (left(myhair,1) ~= "N") then do
  225.             say "Calibrating the Toasters digital phase."
  226.             best=CaliDigitalPhase()
  227.             SWITCHER(DHUE,best)
  228.             SWITCHER(MKHS)
  229.          end
  230.       end
  231.    end
  232.  
  233.    DigitalPhaseError = DeltaHue2Angle(SWITCHER(DH3E))
  234.  
  235.    if(abs(DigitalPhaseError) > 5) then do
  236.       SWITCHER(TOWB)
  237.       say "Your Toaster has a Digital Hue error of "DigitalPhaseError" degrees."
  238.       say "So, the Flyer's playback phase may not be calibrated correctly!"
  239.       say "You should try AutoHueing your Toaster, and then repeat this script."
  240.       SWITCHER(TOSW)
  241.    end
  242. end
  243.  
  244. /*------------------------------------------*/
  245.  
  246. say "Please wait. Calibrating the Flyer's Record Phase."
  247.  
  248. SWITCHER(MDV2)
  249. SWITCHER(PDV1) /* tell it to load into DV1        */
  250. SWITCHER(PAT1) /* Generatate test signal into DV1 */
  251. SWITCHER(MDV1)
  252. SWITCHER(PDV1)
  253. SWITCHER(TOWB)
  254.  
  255.  
  256. /*******************/
  257. /* Auto Record Hue */
  258. address command
  259. FLYER'CalibNew >nil: AR 2'
  260. FLYER'SetPlayMode 0 PLAY'
  261. address
  262.  
  263. if ~exists("ENV:CalibResult") then do
  264.    say
  265.    say "ERROR:"   
  266.    say " The program CalibNew malfunctioned preventing me from calibrating"
  267.    say " your Flyer. This could be caused by:"
  268.    say
  269.    say " 1) Incompatability with your currently installed Amiga OS."
  270.    say "    (I.E. system with an old mathieedoubbas.library in KickStart)" 
  271.    say " 2) Lack of a Flyer in your computer."
  272.    say " 3) Your Flyer software not installed properly"
  273.    say
  274.    call GetOutaHere(" If the problem persists, contact NewTek for help.")
  275.    end
  276.  
  277. open(in,"ENV:CalibResult",'read')
  278. instring = readln(in)
  279. close(in)
  280. parse value instring with RecordPhaseError
  281.  
  282. /*------------------------------------------*/
  283. SWITCHER(TOSW)
  284.  
  285. say "Calibrating the Flyer's Playback Phase on channel 0."
  286. Play0PhaseError=CalibratePlay(0)
  287.  
  288. say "Calibrating the Flyer's Playback Phase on channel 1."
  289. Play1PhaseError=CalibratePlay(1)
  290.  
  291. address command
  292. 'echo >ENV:FlyerCalibResults 'DigitalPhaseError RecordPhaseError Play0PhaseError Play1PhaseError
  293. /* 'type ENV:FlyerCalibResults' */
  294. 'delete >NIL: "'TestClip'"'
  295. address
  296.  
  297. Switcher(TOWB)
  298.  
  299. say "Cleaning up Flyer drives..."
  300.  
  301. address command
  302. FLYER'voidall >NIL:'
  303. address
  304.  
  305. GetOutaHere("Flyer Calibration was successful.")
  306. exit
  307.  
  308. /******************************************************************/
  309. /******************************************************************/
  310. CalibratePlay:
  311.    arg   VidChannel
  312.  
  313. if(VidChannel=0) then do
  314.    SWITCHER(M003)
  315.    SWITCHER(P003)
  316.    grab=IQ30
  317. end
  318. else do
  319.    SWITCHER(M004)
  320.    SWITCHER(P004)
  321.    grab=IQ40
  322. end
  323.  
  324. /*-----------*/
  325. address command
  326. 'c:copy >nil: 'FLYER'SetFloobyCal RAM: quiet'
  327. FLYER'playclip >nil: 0 'VidChannel' 0 "'TestClip'" 0 0 0 1 0'
  328. 'RAM:SetFloobyCal >nil: 'VidChannel' 2 0 0 0 0'
  329. address
  330. /*-----------*/
  331.  
  332. SWITCHER(DIIM)    /* disable imagery */
  333.  
  334. QabsBest= 500000000  /* bogus initial value */
  335. Position=-35
  336.  
  337. do until ((PlayPhaseError < 3) | (Position=0))
  338.    if(Position=-34) then posit="ffde"
  339.    else if(Position=-35) then posit="ffdd"
  340.    else if(Position=-36) then posit="ffdc"
  341.  
  342.    /* set play position  */
  343.    address command
  344.    'RAM:SetFloobyCal >nil: 'VidChannel' 5 0 'posit
  345.    address
  346.  
  347.    do clock=0 to 3
  348.       do coarse=0 to 9
  349.          do fine=0 to 7
  350.             address command
  351.             'RAM:SetFloobyCal >nil: 'VidChannel' 2 0 'clock coarse fine
  352.             address
  353.  
  354.             result=SWITCHER(value(grab))
  355.             parse value result with 1 YPI +4 YPQ +4 YNI +4 YNQ +4
  356.             I0= c2d(YPI)-c2d(YNI)
  357.             Q0= c2d(YPQ)-c2d(YNQ)
  358.             Qabs = abs(Q0)
  359.  
  360.             if((Qabs < QabsBest) & (I0 > 0)) then do
  361.                PositionBest=Position
  362.                positBest=posit
  363.                Ibest=I0
  364.                Qbest=Q0
  365.                QabsBest=Qabs
  366.                ClockBest=clock
  367.                CoarseBest=coarse
  368.                FineBest=fine
  369.             end
  370.          end fine
  371.       end coarse
  372.    end clock
  373.  
  374.    if(Position=-35) then Position=-34
  375.    else if(Position=-34) then Position=-36
  376.    else if(Position=-36) then Position=0
  377.  
  378.    PlayPhaseError = IQ2Hue(Ibest,Qbest)
  379. end
  380.  
  381. SWITCHER(ENIM)    /* enable imagery */
  382.  
  383. /* say "Clock Coarse Fine ="PositionBest ClockBest CoarseBest FineBest */
  384.  
  385. if(abs(PlayPhaseError) > 3) then do
  386. testit:
  387.    say
  388.    say "ERROR:"
  389.    say " A problem was detected during Flyer Play Phase calibration."   
  390.    say " the Play Phase error was "PlayPhaseError" degrees."
  391.    say " You may need to power down, and then try again."
  392.    say
  393.    GetOutaHere(" If the problem persists, contact NewTek for help.")
  394. end
  395.  
  396. /* save it in non-volatile memory */
  397. address command
  398. 'RAM:SetFloobyCal >nil: 'VidChannel' 5 1 'positBest
  399. 'RAM:SetFloobyCal >nil: 'VidChannel' 2 1 'ClockBest CoarseBest FineBest
  400. 'c:delete >nil: RAM:SetFloobyCal quiet'
  401. address
  402.  
  403. return (PlayPhaseError)
  404.  
  405. /******************************************************************/
  406. /******************************************************************/
  407. ConnectLoopBack:
  408.    abort=FALSE
  409.    SWITCHER(TOSW)
  410.  
  411.    do while((abort=FALSE) & (SWITCHER(STAT,V2IS) = 0))
  412.       SWITCHER(TOWB)
  413.       say "Please connect the output of your Toaster to the Toasters Input 2."
  414.       say "Please press <RETURN> when ready. (or enter 'A' to abort)"
  415.       pull myhair
  416.  
  417.       if (left(myhair,1) = "A") then do
  418.          abort=TRUE
  419.          say
  420.          say "WARNING:"
  421.          say " Toaster Digital Hue adjustment has been aborted."
  422.          say " Your Flyer's playback phase may not be calibrated correctly!"
  423.       end
  424.  
  425.       SWITCHER(TOSW)
  426.    end
  427. return(abort)
  428.  
  429. /******************************************************************/
  430. /******************************************************************/
  431. CaliDigitalPhase:
  432.  
  433. abserr=130000  /* bogus error */
  434.  
  435. do dp=0 to 63
  436.    SWITCHER(DHUE,dp)
  437. /* SWITCHER(M003) */
  438.    dperr=SWITCHER(DH3E)       /* signed error */
  439.    absdp=abs(dperr)
  440.  
  441.    if(absdp < abserr) then do
  442.       error=dperr
  443.       abserr=absdp
  444.       best=dp
  445.    end
  446. end
  447.  
  448. /* say "BestDP="best" Error="error */
  449.  
  450. return(best)
  451.  
  452. /******************************************************************/
  453. /******************************************************************/
  454. /* -180 < result < 180 degrees */
  455. polar: procedure
  456.    arg   opposite,adjacent
  457.  
  458.    if adjacent = 0 then do
  459.       if opposite < 0 then return 270
  460.          else return 90
  461.       end
  462.  
  463.    remlib("ToasterARexx.port")
  464.    addlib("rexxmathlib.library",0,-30,0)
  465.    result = 57.29578*atan(opposite/adjacent)
  466.    remlib("rexxmathlib.library")
  467.    addlib("ToasterARexx.port",0)
  468.  
  469.    if adjacent < 0 then result = result + 180
  470. return   result
  471.  
  472. /******************************************************************/
  473. /******************************************************************/
  474. IQ2Hue: procedure
  475.    arg ip,qp
  476.  
  477.    hue = polar(-qp,ip)  /* return degrees from I vector */
  478. return hue
  479.  
  480. /******************************************************************/
  481. /******************************************************************/
  482. DeltaHue2Angle: procedure
  483.    arg   foo
  484.  
  485.    foo = foo/65536
  486.    if (( foo > 1.0 ) | (foo < -1.0)) then result = 3.1416*sign(foo) + arcsine(foo-2*sign(foo))
  487.    else result = arcsine(foo)
  488. return 57.29578*result
  489.  
  490. /******************************************************************/
  491. squareroot: procedure
  492.    arg   param
  493.  
  494.    remlib("ToasterARexx.port")
  495.    addlib("rexxmathlib.library",0,-30,0)
  496.    result = sqrt(param)
  497.    remlib("rexxmathlib.library")
  498.    addlib("ToasterARexx.port",0)
  499. return   result
  500.  
  501. /******************************************************************/
  502. arcsine: procedure
  503.    arg   param
  504.  
  505.    remlib("ToasterARexx.port")
  506.    addlib("rexxmathlib.library",0,-30,0)
  507.    result = asin(param)
  508.    remlib("rexxmathlib.library")
  509.    addlib("ToasterARexx.port",0)
  510. return   result
  511.  
  512.  
  513. /******************************************************************/
  514. /******************************************************************/
  515.  
  516. GetOutaHere:
  517.    parse arg message
  518.  
  519.    remlib("ToasterARexx.port")
  520.    if show('Ports',"ToasterARexx.port") then addlib("ToasterARexx.port" , 0)
  521.    if show('Ports',"ToasterARexx.port") then do
  522.            Switcher(TOSW)
  523.            SWITCHER(NOIQ)
  524.            SWITCHER(TOWB)
  525.    end
  526.  
  527.    say message
  528.  
  529. /**********
  530.    if(TestClip ~= "") then do
  531.       say "Would you like me to delete the "TestClip" clip (Y/N)?"
  532.       pull myhair
  533.       if (left(myhair,1) ~= "N") then do
  534.           address command
  535.           'c:delete >nil: 'TestClip' quiet'
  536.           address
  537.       end
  538.    end
  539.    else do
  540.           say
  541.       say "Press <RETURN> to exit."
  542.       pull myhair
  543.    end
  544. **********/
  545.  
  546.    say
  547.    say "Press <RETURN> to exit."
  548.    pull myhair
  549.    if show('Ports',"ToasterARexx.port") then remlib("ToasterARexx.port")
  550.    exit
  551. return
  552.